<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>MongoDB Retrieve | Introduction</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../home/part2/7.MongoDB查询条件.html" />
    
    
    <link rel="prev" href="../../home/part2/5.MongoDBDelete.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="3.6"
        data-chapter-title="MongoDB Retrieve"
        data-filepath="home/part2/6.MongoDBRetrieve.md"
        data-basepath="../.."
        data-revision="Sun Oct 21 2018 20:49:12 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="home/NoSQL简介.html">
            
                
                    <a href="../../home/NoSQL简介.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        NoSQL介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="home/part1/Redis.html">
            
                
                    <a href="../../home/part1/Redis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        Redis
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="home/part1/1.常用命令.html">
            
                
                    <a href="../../home/part1/1.常用命令.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        常用命令
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="home/part1/2.Redis的数据类型.html">
            
                
                    <a href="../../home/part1/2.Redis的数据类型.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        Redis的数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="home/part1/3.Redis高级.html">
            
                
                    <a href="../../home/part1/3.Redis高级.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        Redis高级
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="home/part1/4.python操作redis.html">
            
                
                    <a href="../../home/part1/4.python操作redis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        python操作redis
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="home/part2/MongoDB.html">
            
                
                    <a href="../../home/part2/MongoDB.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        MongoDB
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="home/part2/1.MongoDB基础操作.html">
            
                
                    <a href="../../home/part2/1.MongoDB基础操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        MongoDB基础操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="home/part2/2.MongoDBDBS.html">
            
                
                    <a href="../../home/part2/2.MongoDBDBS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        MongoDB DBS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="home/part2/3.MongoDBCreate.html">
            
                
                    <a href="../../home/part2/3.MongoDBCreate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        MongoDB Create
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="home/part2/4.MongoDBUpdate.html">
            
                
                    <a href="../../home/part2/4.MongoDBUpdate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        MongoDB Update
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="home/part2/5.MongoDBDelete.html">
            
                
                    <a href="../../home/part2/5.MongoDBDelete.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        MongoDB Delete
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="3.6" data-path="home/part2/6.MongoDBRetrieve.html">
            
                
                    <a href="../../home/part2/6.MongoDBRetrieve.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        MongoDB Retrieve
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="home/part2/7.MongoDB查询条件.html">
            
                
                    <a href="../../home/part2/7.MongoDB查询条件.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        MongoDB 查询条件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="home/part2/8.MongoDBIndex.html">
            
                
                    <a href="../../home/part2/8.MongoDBIndex.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        MongoDB Index
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="home/part2/9.MongoDBDump.html">
            
                
                    <a href="../../home/part2/9.MongoDBDump.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        MongoDB Dump
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="home/part2/10.Python操作MongoDB.html">
            
                
                    <a href="../../home/part2/10.Python操作MongoDB.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        Python操作MongoDB
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >Introduction</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="mongodb-&#x67E5;&#x8BE2;&#x6587;&#x6863;">MongoDB &#x67E5;&#x8BE2;&#x6587;&#x6863;</h1>
<p>MongoDB &#x67E5;&#x8BE2;&#x6587;&#x6863;&#x4F7F;&#x7528; find() &#x65B9;&#x6CD5;&#x3002;</p>
<p>find() &#x65B9;&#x6CD5;&#x4EE5;&#x975E;&#x7ED3;&#x6784;&#x5316;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x663E;&#x793A;&#x6240;&#x6709;&#x6587;&#x6863;&#x3002;</p>
<hr>
<h2 id="&#x8BED;&#x6CD5;">&#x8BED;&#x6CD5;</h2>
<p>MongoDB &#x67E5;&#x8BE2;&#x6570;&#x636E;&#x7684;&#x8BED;&#x6CD5;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-sql">db.collection.find(query, projection)
</code></pre>
<ul>
<li><strong>query</strong> &#xFF1A;&#x53EF;&#x9009;&#xFF0C;&#x4F7F;&#x7528;&#x67E5;&#x8BE2;&#x64CD;&#x4F5C;&#x7B26;&#x6307;&#x5B9A;&#x67E5;&#x8BE2;&#x6761;&#x4EF6;</li>
<li><strong>projection</strong> &#xFF1A;&#x53EF;&#x9009;&#xFF0C;&#x4F7F;&#x7528;&#x6295;&#x5F71;&#x64CD;&#x4F5C;&#x7B26;&#x6307;&#x5B9A;&#x8FD4;&#x56DE;&#x7684;&#x952E;&#x3002;&#x67E5;&#x8BE2;&#x65F6;&#x8FD4;&#x56DE;&#x6587;&#x6863;&#x4E2D;&#x6240;&#x6709;&#x952E;&#x503C;&#xFF0C; &#x53EA;&#x9700;&#x7701;&#x7565;&#x8BE5;&#x53C2;&#x6570;&#x5373;&#x53EF;&#xFF08;&#x9ED8;&#x8BA4;&#x7701;&#x7565;&#xFF09;&#x3002;</li>
</ul>
<p>&#x5982;&#x679C;&#x4F60;&#x9700;&#x8981;&#x4EE5;&#x6613;&#x8BFB;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x8BFB;&#x53D6;&#x6570;&#x636E;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; pretty() &#x65B9;&#x6CD5;&#xFF0C;&#x8BED;&#x6CD5;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-sql">&gt;db.col.find().pretty()
</code></pre>
<p>pretty() &#x65B9;&#x6CD5;&#x4EE5;&#x683C;&#x5F0F;&#x5316;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x663E;&#x793A;&#x6240;&#x6709;&#x6587;&#x6863;&#x3002;</p>
<h2 id="&#x5B9E;&#x4F8B;">&#x5B9E;&#x4F8B;</h2>
<p>&#x4EE5;&#x4E0B;&#x5B9E;&#x4F8B;&#x6211;&#x4EEC;&#x67E5;&#x8BE2;&#x4E86;&#x96C6;&#x5408; col &#x4E2D;&#x7684;&#x6570;&#x636E;&#xFF1A;</p>
<pre><code class="lang-sql">&gt; db.col.find().pretty()
{
    &quot;_id&quot; : ObjectId(&quot;56063f17ade2f21f36b03133&quot;),
    &quot;title&quot; : &quot;MongoDB &#x6559;&#x7A0B;&quot;,
    &quot;description&quot; : &quot;MongoDB &#x662F;&#x4E00;&#x4E2A; Nosql &#x6570;&#x636E;&#x5E93;&quot;,
    &quot;by&quot; : &quot;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&quot;,
    &quot;url&quot; : &quot;http://www.runoob.com&quot;,
    &quot;tags&quot; : [
            &quot;mongodb&quot;,
            &quot;database&quot;,
            &quot;NoSQL&quot;
    ],
    &quot;likes&quot; : 100
}
</code></pre>
<p>&#x9664;&#x4E86; find() &#x65B9;&#x6CD5;&#x4E4B;&#x5916;&#xFF0C;&#x8FD8;&#x6709;&#x4E00;&#x4E2A; findOne() &#x65B9;&#x6CD5;&#xFF0C;&#x5B83;&#x53EA;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6587;&#x6863;&#x3002;</p>
<hr>
<h2 id="mongodb-&#x4E0E;-rdbms-where-&#x8BED;&#x53E5;&#x6BD4;&#x8F83;">MongoDB &#x4E0E; RDBMS Where &#x8BED;&#x53E5;&#x6BD4;&#x8F83;</h2>
<p>&#x5982;&#x679C;&#x4F60;&#x719F;&#x6089;&#x5E38;&#x89C4;&#x7684; SQL &#x6570;&#x636E;&#xFF0C;&#x901A;&#x8FC7;&#x4E0B;&#x8868;&#x53EF;&#x4EE5;&#x66F4;&#x597D;&#x7684;&#x7406;&#x89E3; MongoDB &#x7684;&#x6761;&#x4EF6;&#x8BED;&#x53E5;&#x67E5;&#x8BE2;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x64CD;&#x4F5C;</th>
<th>&#x683C;&#x5F0F;</th>
<th>&#x8303;&#x4F8B;</th>
<th>RDBMS&#x4E2D;&#x7684;&#x7C7B;&#x4F3C;&#x8BED;&#x53E5;</th>
</tr>
</thead>
<tbody>
<tr>
<td>&#x7B49;&#x4E8E;</td>
<td><code>{&lt;key&gt;:&lt;value&gt;}</code></td>
<td><code>db.col.find({&quot;by&quot;:&quot;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&quot;}).pretty()</code></td>
<td>where by = &apos;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&apos;</td>
</tr>
<tr>
<td>&#x5C0F;&#x4E8E;</td>
<td><code>{&lt;key&gt;:{$lt:&lt;value&gt;}}</code></td>
<td><code>db.col.find({&quot;likes&quot;:{$lt:50}}).pretty()</code></td>
<td>where likes &lt; 50</td>
</tr>
<tr>
<td>&#x5C0F;&#x4E8E;&#x6216;&#x7B49;&#x4E8E;</td>
<td><code>{&lt;key&gt;:{$lte:&lt;value&gt;}}</code></td>
<td><code>db.col.find({&quot;likes&quot;:{$lte:50}}).pretty()</code></td>
<td>where likes &lt;= 50</td>
</tr>
<tr>
<td>&#x5927;&#x4E8E;</td>
<td><code>{&lt;key&gt;:{$gt:&lt;value&gt;}}</code></td>
<td><code>db.col.find({&quot;likes&quot;:{$gt:50}}).pretty()</code></td>
<td>where likes &gt; 50</td>
</tr>
<tr>
<td>&#x5927;&#x4E8E;&#x6216;&#x7B49;&#x4E8E;</td>
<td><code>{&lt;key&gt;:{$gte:&lt;value&gt;}}</code></td>
<td><code>db.col.find({&quot;likes&quot;:{$gte:50}}).pretty()</code></td>
<td>where likes &gt;= 50</td>
</tr>
<tr>
<td>&#x4E0D;&#x7B49;&#x4E8E;</td>
<td><code>{&lt;key&gt;:{$ne:&lt;value&gt;}}</code></td>
<td><code>db.col.find({&quot;likes&quot;:{$ne:50}}).pretty()</code></td>
<td>where likes != 50</td>
</tr>
</tbody>
</table>
<hr>
<h2 id="mongodb-and-&#x6761;&#x4EF6;">MongoDB AND &#x6761;&#x4EF6;</h2>
<p>MongoDB &#x7684; find() &#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x4F20;&#x5165;&#x591A;&#x4E2A;&#x952E;(key)&#xFF0C;&#x6BCF;&#x4E2A;&#x952E;(key)&#x4EE5;&#x9017;&#x53F7;&#x9694;&#x5F00;&#xFF0C;&#x53CA;&#x5E38;&#x89C4; SQL &#x7684; AND &#x6761;&#x4EF6;&#x3002;</p>
<p>&#x8BED;&#x6CD5;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-sql">&gt;db.col.find({key1:value1, key2:value2}).pretty()
</code></pre>
<h2 id="&#x5B9E;&#x4F8B;">&#x5B9E;&#x4F8B;</h2>
<p>&#x4EE5;&#x4E0B;&#x5B9E;&#x4F8B;&#x901A;&#x8FC7;<strong>by</strong>&#x548C;<strong>title</strong>&#x952E;&#x6765;&#x67E5;&#x8BE2;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&#x4E2D;MongoDB &#x6559;&#x7A0B;&#x7684;&#x6570;&#x636E;</p>
<pre><code class="lang-sql">&gt; db.col.find({&quot;by&quot;:&quot;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&quot;, &quot;title&quot;:&quot;MongoDB &#x6559;&#x7A0B;&quot;}).pretty()
{
    &quot;_id&quot; : ObjectId(&quot;56063f17ade2f21f36b03133&quot;),
    &quot;title&quot; : &quot;MongoDB &#x6559;&#x7A0B;&quot;,
    &quot;description&quot; : &quot;MongoDB &#x662F;&#x4E00;&#x4E2A; Nosql &#x6570;&#x636E;&#x5E93;&quot;,
    &quot;by&quot; : &quot;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&quot;,
    &quot;url&quot; : &quot;http://www.runoob.com&quot;,
    &quot;tags&quot; : [
            &quot;mongodb&quot;,
            &quot;database&quot;,
            &quot;NoSQL&quot;
    ],
    &quot;likes&quot; : 100
}
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x4E2D;&#x7C7B;&#x4F3C;&#x4E8E; WHERE &#x8BED;&#x53E5;&#xFF1A;<strong>WHERE by=&apos;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&apos; AND title=&apos;MongoDB &#x6559;&#x7A0B;&apos;</strong></p>
<hr>
<h2 id="mongodb-or-&#x6761;&#x4EF6;">MongoDB OR &#x6761;&#x4EF6;</h2>
<p>MongoDB OR &#x6761;&#x4EF6;&#x8BED;&#x53E5;&#x4F7F;&#x7528;&#x4E86;&#x5173;&#x952E;&#x5B57; <strong>$or</strong>,&#x8BED;&#x6CD5;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-sql">&gt;db.col.find(
   {
      $or: [
         {key1: value1}, {key2:value2}
      ]
   }
).pretty()
</code></pre>
<h2 id="&#x5B9E;&#x4F8B;">&#x5B9E;&#x4F8B;</h2>
<p>&#x4EE5;&#x4E0B;&#x5B9E;&#x4F8B;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x6F14;&#x793A;&#x4E86;&#x67E5;&#x8BE2;&#x952E;by&#x503C;&#x4E3A; &#x83DC;&#x9E1F;&#x6559;&#x7A0B; &#x6216;&#x952E;title&#x503C;&#x4E3A;MongoDB &#x6559;&#x7A0B;&#x7684;&#x6587;&#x6863;&#x3002;</p>
<pre><code class="lang-sql">&gt;db.col.find({$or:[{&quot;by&quot;:&quot;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&quot;},{&quot;title&quot;: &quot;MongoDB &#x6559;&#x7A0B;&quot;}]}).pretty()
{
    &quot;_id&quot; : ObjectId(&quot;56063f17ade2f21f36b03133&quot;),
    &quot;title&quot; : &quot;MongoDB &#x6559;&#x7A0B;&quot;,
    &quot;description&quot; : &quot;MongoDB &#x662F;&#x4E00;&#x4E2A; Nosql &#x6570;&#x636E;&#x5E93;&quot;,
    &quot;by&quot; : &quot;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&quot;,
    &quot;url&quot; : &quot;http://www.runoob.com&quot;,
    &quot;tags&quot; : [
            &quot;mongodb&quot;,
            &quot;database&quot;,
            &quot;NoSQL&quot;
    ],
    &quot;likes&quot; : 100
}
&gt;
</code></pre>
<hr>
<h2 id="and-&#x548C;-or-&#x8054;&#x5408;&#x4F7F;&#x7528;">AND &#x548C; OR &#x8054;&#x5408;&#x4F7F;&#x7528;</h2>
<p>&#x4EE5;&#x4E0B;&#x5B9E;&#x4F8B;&#x6F14;&#x793A;&#x4E86; AND &#x548C; OR &#x8054;&#x5408;&#x4F7F;&#x7528;&#xFF0C;&#x7C7B;&#x4F3C;&#x5E38;&#x89C4; SQL &#x8BED;&#x53E5;&#x4E3A;&#xFF1A;<strong>&apos;where likes&gt;50 AND (by = &apos;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&apos; OR title = &apos;MongoDB &#x6559;&#x7A0B;&apos;)&apos;</strong></p>
<pre><code class="lang-sql">&gt;db.col.find({&quot;likes&quot;: {$gt:50}, $or: [{&quot;by&quot;: &quot;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&quot;},{&quot;title&quot;: &quot;MongoDB &#x6559;&#x7A0B;&quot;}]}).pretty()
{
    &quot;_id&quot; : ObjectId(&quot;56063f17ade2f21f36b03133&quot;),
    &quot;title&quot; : &quot;MongoDB &#x6559;&#x7A0B;&quot;,
    &quot;description&quot; : &quot;MongoDB &#x662F;&#x4E00;&#x4E2A; Nosql &#x6570;&#x636E;&#x5E93;&quot;,
    &quot;by&quot; : &quot;&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&quot;,
    &quot;url&quot; : &quot;http://www.runoob.com&quot;,
    &quot;tags&quot; : [
            &quot;mongodb&quot;,
            &quot;database&quot;,
            &quot;NoSQL&quot;
    ],
    &quot;likes&quot; : 100
}
</code></pre>
<h2 id="&#x5B9E;&#x4F8B;&#x7EC3;&#x4E60;">&#x5B9E;&#x4F8B;&#x7EC3;&#x4E60;</h2>
<pre><code class="lang-sql">&#x67E5;&#x8BE2;user&#x96C6;&#x5408;&#x4E2D; uname=&quot;&#x5F20;&#x4E09;&quot; and age=21 &#x7684;&#x6240;&#x6709;&#x6587;&#x6863;
&gt; db.user.find({&quot;uname&quot;:&quot;zhangsan&quot;,&quot;age&quot;:21}).pretty()


&#x67E5;&#x8BE2;user&#x96C6;&#x5408;&#x4E2D; uname=zhangsan &#x6216;&#x8005; uname=&quot;&#x5F20;&#x4E09;&quot;&#x7684;&#x6570;&#x636E;
&gt;db.user.find({$or:[{&quot;uname&quot;:&quot;zhangsan&quot;},{&quot;uname&quot;: &quot;&#x5F20;&#x4E09;&quot;}]}).pretty()


&#x67E5;&#x8BE2;user&#x96C6;&#x5408;&#x4E2D; age=21  uname=&#x5F20;&#x4E09;&#x6216;uname=zhangsan
&gt;db.user.find({&quot;age&quot;:21,$or:[{&quot;uname&quot;:&quot;zhangsan&quot;},{&quot;uname&quot;: &quot;&#x5F20;&#x4E09;&quot;}]}).pretty()


&#x9650;&#x5236;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;&#x5B57;&#x6BB5; 
&gt; db.user.find({&quot;uname&quot;:&quot;zhangsan&quot;,&quot;age&quot;:21},{&quot;_id&quot;:1,&quot;uname&quot;:1}).pretty()
{ &quot;_id&quot; : ObjectId(&quot;59f02a93efa271499313b6a4&quot;), &quot;uname&quot; : &quot;zhangsan&quot; }
{ &quot;_id&quot; : ObjectId(&quot;59f02abbefa271499313b6a5&quot;), &quot;uname&quot; : &quot;zhangsan&quot; }
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../home/part2/5.MongoDBDelete.html" class="navigation navigation-prev " aria-label="Previous page: MongoDB Delete"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../home/part2/7.MongoDB查询条件.html" class="navigation navigation-next " aria-label="Next page: MongoDB 查询条件"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
